package com.example.newdemo.net.model;


import com.example.newdemo.net.api.ApiService;
import com.example.newdemo.net.jsonConverter.JSONConverterFactory;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpManager {

    private final static String URL_String = "https://www.aixiaoyi123.com/hbjpt_sit/tch/";

    private Retrofit mRetrofit;

    private HttpManager(){
        init();
    }

    private static class HttpManageHolder{
        private static HttpManager HTTP_MANAGER = new HttpManager();
    }


    public static HttpManager getInstance(){
        return HttpManageHolder.HTTP_MANAGER;
    }

    private void init() {
        HttpSetting httpSetting =new HttpSetting();

        OkHttpClient httpClient = httpSetting.getDefaultOkHttpClient();

        mRetrofit = new Retrofit.Builder()
                .baseUrl(URL_String)        // http url
                .client(httpClient)
                .addConverterFactory(JSONConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    }


    public ApiService getApiService(){
        return mRetrofit.create(ApiService.class);
    }





}
